package com.hqyj.springBoot.modules.account.controller;

import com.hqyj.springBoot.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AccountController {

    @Autowired
    private UserService userService;

    /**
     * 127.0.0.1/login ---- get
     */
    @GetMapping("/login")
    public String loginPage(ModelMap modelMap){
        /*设置modelMap是因为前几个组装页面是通过拦截器的路径来实现的他只会找
        templates文件夹跟目录下的碎片组装器，所以要手动的设置login路径*/
        modelMap.addAttribute("page","account/login");
        return "indexSimple";
    }

    /**
     * 127.0.0.1/logout ---- get
     */
    @GetMapping("/logout")
    public String logout(){
        userService.logout();
        return "redirect:/login";
    }

    /**
     * 127.0.0.1/register ---- get
     */
    @GetMapping("/register")
    public String registerPage(ModelMap modelMap){
        modelMap.addAttribute("page","account/register");
        return "indexSimple";
    }

    /**
     * 127.0.0.1/account/userList ---- get
     * admin,manager 是数库的角色信息 OR 是当中的任意一个角色就能访问（AND是必须同时具备连个角色才能访问）
     */
    @GetMapping("/account/userList")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String userListPage(){
        return "index";
    }

    /**
     * 127.0.0.1/account/resourceList ---- get
     * admin,manager 是数库的角色信息 OR 是当中的任意一个角色就能访问（AND是必须同时具备连个角色才能访问）
     */
    @GetMapping("/account/resourceList")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String resourceListPage(){
        return "index";
    }

    /**
     * 127.0.0.1/account/roleList ---- get
     * admin,manager 是数库的角色信息 OR 是当中的任意一个角色就能访问（AND是必须同时具备连个角色才能访问）
     */
    @GetMapping("/account/roleList")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String roleListPage(){
        return "index";
    }

    /**
     * 127.0.0.1/account/profile ---- get
     */
    @GetMapping("/account/profile")
    public String profilePage(ModelMap modelMap){
//        modelMap.addAttribute("page","account/profile");
        return "index";
    }
}
